export default{
	// data(){
	// 	return{
	// 		//水泥标号
	// 		gradeList:[],
	// 		//浇筑部位
	// 		positionList:[],
	// 		//供应商列表
	// 		supplierList:[],
	// 	}
	// },
	computed:{
		supplierName(){
			return function(val){
				let obj = this.supplierList.find(item => {
					return item.value == val
				})
				return obj ? obj.label : ''
			}
		},
		positionName(){
			return function(val){
				let obj = this.positionList.find(item => {
					return item.value == val
				})
				return obj ? obj.label : ''
			}
		},
		gradeName(){
			return function(val){
				let obj = this.gradeList.find(item => {
					return item.value == val
				})
				return obj ? obj.label : ''
			}
		}
	},
	methods:{
		//获取物料类型
		getCementType(){
			return new Promise((resolve,reject) => {
				if(this.gradeList.length > 0){
					resolve()
				}else{
					this.$u.api.getCementType({current:0,size:100}).then(res => {
						if(res.code != 0){
							this.$u.toast(res.msg)
							return false
						}
						let arr = []
						res.data.records.map(item => {
							arr.push(item.name)
						})
						this.$u.vuex('gradeList', arr);
						// this.gradeList = arr
						resolve()
					}).catch(()=>{
						reject()
					})
				}
				
			})
		},
		//获取地图位置
		getPositionList(){
			return new Promise((resolve,reject) => {
				if(this.positionList.length > 0){
					resolve()
				}else{
					this.$u.api.getPositionList({current:0,size:100}).then(res => {
						if(res.code != 0){
							this.$u.toast(res.msg)
							return false
						}
						let arr = []
						res.data.records.map(item => {
							arr.push({
								value:item.id,
								label:item.name
							})
						})
						this.$u.vuex('positionList', arr);
						//this.positionList = arr
						resolve()
					}).catch(()=>{
						reject()
					})
				}
				
			})
		},
		//获取供应商列表
		getSupplierList(){
			return new Promise((resolve,reject) => {
				if(this.supplierList.length > 0){
					resolve()
				}else{
					this.$u.api.getSupplierList({current:0,size:100}).then(res => {
						if(res.code != 0){
							this.$u.toast(res.msg)
							return false
						}
						let arr = []
						res.data.records.map(item => {
							arr.push({
								value:item.id,
								label:item.name
							})
						})
						this.$u.vuex('supplierList', arr);
						// this.supplierList = arr
						resolve()
					}).catch(()=>{
						reject()
					})
				}
				
			})
		}
	}
}